<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/09/20 23:46:58 $)
// $RCSfile: monitor_loop.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

$template->loadLanguageSection("livesupport");

require_once ("./modules/livesupport/global_listing.php");

$viscount = 0;
foreach ($sessiondata as $key=>$val)
{
	$viscount++;
	$sessionid = $key;
	$visdata = array();
	$totalfootprints = count($footprints[$sessionid]);

	if (in_array($val["sessionid"], $pendingchatvisitorsessionlist))
	{
		$visdata["incomingchat"] = true;
		$visdata["inchat"] = false;
		$visdata["state"] = $_SWIFT["language"]["incomingchat"];
		$visdata["chatterid"] = $pendingvisitordata[$val["sessionid"]]["userfullname"];
		$visdata["chatsessionid"] = $pendingvisitordata[$val["sessionid"]]["chatsessionid"];
		$visdata["department"] = $pendingvisitordata[$val["sessionid"]]["departmenttitle"];
		$visdata["visstate"] = STATE_PENDINGCHAT;
	} else if (in_array($val["sessionid"], $inchatvisitorsessionlist)) {
		$visdata["incomingchat"] = "false";
		$visdata["inchat"] = "true";
		$visdata["state"] = $_SWIFT["language"]["inchat"];
		$visdata["chatterid"] = $inchatvisitordata[$val["sessionid"]]["userfullname"];
		$visdata["chatsessionid"] = $inchatvisitordata[$val["sessionid"]]["chatsessionid"];
		$visdata["department"] = $inchatvisitordata[$val["sessionid"]]["departmenttitle"];	
		$visdata["staffname"] = $inchatvisitordata[$val["sessionid"]]["staffname"];	
		$visdata["visstate"] = STATE_INCHAT;
	} else {
		$visdata["incomingchat"] = "false";
		$visdata["inchat"] = "false";
		$visdata["state"] = $_SWIFT["language"]["browsing"];
		$visdata["chatterid"] = $val["ipaddress"];
		$visdata["chatsessionid"] = "NULL";
		$visdata["department"] = "NULL";
		$visdata["visstate"] = STATE_BROWSING;
	}

	$customjs .= 'window.parent.parseVisitor("'. $val["sessionid"] .'", "'. addslashes($visdata["chatterid"]) .'", "'. addslashes($visdata["state"]) .'", "'. addslashes($val["currentpage"]) .'", "'. addslashes($val["pagetitle"]) .'", "'. addslashes($val["referrer"]) .'", "'. addslashes($val["countryname"]) .'", "'. addslashes($val["browsercode"]) .'", "'. addslashes($val["max"]-$val["min"]) .'", "'. addslashes($visdata["visstate"]) .'");'.SWIFT_CRLF;

	$fpid = 0;
	for ($ii=0; $ii<count($footprints[$sessionid]); $ii++) {
		$fpid++;
		$customjs .= 'window.parent.addFootprint("'. $val["sessionid"] .'", "'. addslashes($footprints[$sessionid][$ii]["pageurl"]) .'", "'. addslashes($footprints[$sessionid][$ii]["referrer"]) .'");';
	}
}

require_once ("./includes/TreeMenu/TreeMenu.php");

$icon = 'icon_onlineofflinestaff.gif';
$expandedIcon = 'icon_onlineofflinestaff.gif';

$menu  = new HTML_TreeMenu();

$node1   = new HTML_TreeNode(array('text' => "&nbsp;Online/Offline Staff", 'link' => "", 'icon' => $icon, 'expandedIcon' => $expandedIcon, 'expanded' => true));

$menu->addItem($node1);
	
// Create the presentation class
$treeMenu = &new HTML_TreeMenu_DHTML($menu, array('images' => stripTrailingSlash($_SWIFT["themepath"]), 'defaultClass' => 'treeMenuDefault'));

ob_start();
$treeMenu->printMenu();
$treecontents = ob_get_contents();
ob_end_clean();
//$customjs .= 'window.parent.updateStaffTree("'. addslashes(preg_replace("#(\r\n|\r|\n)#s", "", $treecontents)) .'");';
?><html>
<head>
<title>Loop Frame</title>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $_SWIFT["language"]["charset"]; ?>">
<!-- default javascript -->
<script language="Javascript" src="<?php echo $_SWIFT["themepath"]; ?>main.js"></script>
<script type="text/javascript" src="<?php echo $_SWIFT["swiftpath"] ?>includes/TreeMenu/TreeMenu.js"></script>
</head>

<body onLoad="pushData()" bgcolor="#0000FF">
<script language="Javascript">
function loopFrame() {
	if (browsercode == "IE" || browsercode == "MO") {
		window.location.reload(true);
	} else {
		window.location.href = "<?php echo $_SWIFT["swiftpath"]; ?>monitor/index.php?_m=livesupport&_a=monitorloop&sessionid=<?php echo $_SWIFT["session"]["sessionid"]; ?>&randno="+doRand();
	}
}

function pushData()
{
	if (!window.parent)
	{
		return;
	}

	window.parent.looploaded = true;

	<?
	echo $customjs;
	?>
	window.parent.endUpdate();
	<?
	if ($noloop != true)
	{
	?>
	setTimeout("loopFrame();", 15000);
	<?
	}	
	?>
}
</script>
Debug Frame
</body>
</html>